package com.hnote.hnoteapplication.ui.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.util.Log;
import android.view.View;

import com.hnote.hnoteapplication.R;
import com.hnote.hnoteapplication.adapter.MenuAdapter;
import com.hnote.hnoteapplication.base.BaseFragment;
import com.hnote.hnoteapplication.base.BaseQuickAdapter;
import com.hnote.hnoteapplication.databinding.FragmentMenuBinding;
import com.hnote.hnoteapplication.entity.MenuItem;
import com.hnote.hnoteapplication.ui.activity.CalculatorActivity;
import com.hnote.hnoteapplication.ui.activity.MainActivity;
import com.hnote.hnoteapplication.ui.activity.SnowActivity;
import com.hnote.hnoteapplication.view.adapter.listener.OnItemClickListener;
import com.hnote.hnoteapplication.view.widget.HNoteDialog;

import java.util.ArrayList;
import java.util.List;


/**
 * 描述：MenuFragment
 * 作者：HNote
 * 邮箱：liupengfei930311@163.com
 * 日期：2017-03-07 下午10:21
 **/
public class MenuFragment extends BaseFragment<FragmentMenuBinding> {

    private static final Class<?>[] ACTIVITY = {CalculatorActivity.class, SnowActivity.class, SnowActivity.class, SnowActivity.class, MainActivity.class, MainActivity.class, MainActivity.class, MainActivity.class, MainActivity.class, MainActivity.class};
    private static final String[] NAME = {"计算器", "计算器", "计算器", "计算器", "计算器", "计算器", "计算器", "计算器", "计算器", "计算器"};
    private static final int[] IMG = {R.mipmap.jisuanqi, R.mipmap.jisuanqi, R.mipmap.jisuanqi, R.mipmap.jisuanqi, R.mipmap.jisuanqi, R.mipmap.jisuanqi, R.mipmap.jisuanqi, R.mipmap.jisuanqi, R.mipmap.jisuanqi, R.mipmap.jisuanqi,};

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_menu;
    }

    @Override
    protected void initView() {
        super.initView();

        BaseQuickAdapter meunAdapter = new MenuAdapter(R.layout.menu_item, getmDataList());

        mViewBinding.recycleView.setHasFixedSize(true);
        mViewBinding.recycleView.setLayoutManager(new GridLayoutManager(mActivity, 2));
        mViewBinding.recycleView.setAdapter(meunAdapter);

        mViewBinding.recycleView.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, final int position) {
                HNoteDialog dialog = new HNoteDialog(mActivity, new HNoteDialog.HNoteClick() {
                    @Override
                    public void confirmClick() {
                        Log.e("test", "ok");
                        startActivity(new Intent(mActivity, ACTIVITY[position]));
                        mActivity.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
                    }

                    @Override
                    public void cancelClick() {
                        Log.e("test", "cancel");
                    }
                });
                dialog.customDialog("确定", "取消", "温馨提示！", "给我一个摸摸大");
            }
        });
    }

    @Override
    protected void initData(Bundle arguments) {
        super.initData(arguments);
    }

    private List<MenuItem> getmDataList() {
        List<MenuItem> mDataList = new ArrayList<>();
        for (int i = 0; i < NAME.length; i++) {
            MenuItem item = new MenuItem();
            item.setName(NAME[i]);
            item.setActivity(ACTIVITY[i]);
            item.setImageResource(IMG[i]);
            mDataList.add(item);
        }

        return mDataList;
    }
}
